package com.popcorn.notice.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.popcorn.action.Action;
import com.popcorn.action.ActionForward;
import com.popcorn.notice.dao.NoticeDAO;
import com.popcorn.notice.model.NoticeModel;

public class NoticeAddAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		NoticeDAO noticeDAO = new NoticeDAO();
		NoticeModel noticeModel = new NoticeModel();
		ActionForward forward = new ActionForward();
		
   		boolean result=false;
   		
   		try{	
   			noticeModel.setTITLE(request.getParameter("TITLE"));
   			noticeModel.setCONTENT(request.getParameter("CONTENT"));
   			noticeModel.setREG_DTM(request.getParameter("REG_DTM"));
   			noticeModel.setREG_ID(request.getParameter("REG_ID"));

   			result=noticeDAO.modelInsert(noticeModel);
   			System.out.println("============NoticeAddAction============");
   			System.out.println("1."+request.getParameter("REG_DTM"));
	   		if(result==false){
	   			System.out.println("DB 등록 실패");
	   			return null;
	   		}
	   		System.out.println("DB 등록 성공");
	   		
	   		forward.setRedirect(true);
	   		forward.setPath("NoticeListDB.ao"); 
	   		return forward;
	   		
  		}catch(Exception ex){
   			ex.printStackTrace();
   		}
		
		return null;
	}

}
